﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


namespace Tesla.Graphics.Implementation {
    /// <summary>
    /// Abstract class for concrete subclasses to provide the underlying implementation of <see cref="Texture1D"/>.
    /// </summary>
    public abstract class Texture1DImplementation : GraphicsResourceImplementation {
        private SurfaceFormat _format;
        private int _width;

        /// <summary>
        /// Gets the format of the texture resource.
        /// </summary>
        public SurfaceFormat Format {
            get {
                return _format;
            }
        }

        /// <summary>
        /// Gets the number of mip map levels in the texture resource.
        /// </summary>
        public abstract int MipCount {
            get;
        }


        /// <summary>
        /// Gets the texture width, in pixels.
        /// </summary>
        public int Width {
            get {
                return _width;
            }
        }

        /// <summary>
        /// Creates a new instance of <see cref="Texture1DImplementation"/>.
        /// </summary>
        /// <param name="width">The texture width in pixels.</param>
        /// <param name="format">The surface format.</param>
        public Texture1DImplementation(int width, SurfaceFormat format) {
            _width = width;
            _format = format;
        }

        /// <summary>
        /// Gets the data from the texture.
        /// </summary>
        /// <typeparam name="T">Type of data in the array.</typeparam>
        /// <param name="data">Array of data</param>
        /// <param name="mipLevel">Mip map level to access</param>
        /// <param name="left">The left-most position in the texture at which to access. (0 or greater)</param>
        /// <param name="right">The right-most position in the texture at which to acess. (width or less)</param>
        /// <param name="startIndex">Starting index in the array to start writing to.</param>
        /// <param name="elementCount">Number of elements to read.</param>
        public abstract void GetData<T>(T[] data, int mipLevel, int left, int right, int startIndex, int elementCount) where T : struct;

        /// <summary>
        /// Sets the data from the array to the texture.
        /// </summary>
        /// <typeparam name="T">Type of data in the array.</typeparam>
        /// <param name="data">Array of data</param>
        /// <param name="mipLevel">Mip map level to access</param>
        /// <param name="left">The left-most position in the 1D texture at which to access. (0 or greater)</param>
        /// <param name="right">The right-most position in the 1D texture at which to acess. (width or less)</param>
        /// <param name="startIndex">Starting index in the array to start reading from.</param>
        /// <param name="elementCount">Number of elements to write.</param>
        public abstract void SetData<T>(T[] data, int mipLevel, int left, int right, int startIndex, int elementCount) where T : struct;
    }
}
